package cn.lf.android.lawfirm.changeapproval.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhy.autolayout.AutoRelativeLayout;

import java.util.List;

import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.changeapproval.modle.ChangeLawyerFeeInfo;
import cn.lf.android.lawfirm.undertake.approval.modle.LawyerFee;
import cn.lf.android.lawfirm.view.DashedLine;

import static cn.lf.android.lawfirm.R.id.charging_mode;
import static cn.lf.android.lawfirm.R.id.creat_people;
import static cn.lf.android.lawfirm.R.id.dline;
import static cn.lf.android.lawfirm.R.id.fukuan;
import static cn.lf.android.lawfirm.R.id.head_left;
import static cn.lf.android.lawfirm.R.id.hetong;
import static cn.lf.android.lawfirm.R.id.payment_method;
import static cn.lf.android.lawfirm.R.id.shoufei;
import static cn.lf.android.lawfirm.R.id.total;

public class BeforeLawyerFeeAdapter extends BaseAdapter {
    private List<LawyerFee> list;
    private LayoutInflater inflater;
    private Activity context;
    /**
     * 0-承办审批
     **/
    private int type;

    public BeforeLawyerFeeAdapter(Activity context, List<LawyerFee> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_after_law_distribution, null);
            holder.names = (TextView) convertView
                    .findViewById(R.id.names);
            holder.team = (TextView) convertView
                    .findViewById(R.id.team);
            holder.creat_people = (TextView) convertView
                    .findViewById(creat_people);
            holder.right_two = (TextView) convertView
                    .findViewById(R.id.right_two);
            holder.right_one = (TextView) convertView
                    .findViewById(R.id.right_one);
            holder.head_right = (TextView) convertView
                    .findViewById(R.id.head_right);
            holder.head_left = (TextView) convertView
                    .findViewById(head_left);
            holder.total = (TextView) convertView
                    .findViewById(total);
            holder.charging_mode = (TextView) convertView
                    .findViewById(charging_mode);
            holder.payment_method = (TextView) convertView
                    .findViewById(payment_method);
            holder.hetong = (AutoRelativeLayout) convertView
                    .findViewById(hetong);
            holder.shoufei = (AutoRelativeLayout) convertView
                    .findViewById(shoufei);
            holder.fukuan = (AutoRelativeLayout) convertView
                    .findViewById(fukuan);
            holder.dline = (DashedLine) convertView
                    .findViewById(dline);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final LawyerFee bean = list.get(position);
        if (position != 0&&"0".equals(bean.isFirst)) {
            holder.dline.setVisibility(View.VISIBLE);
        } else {
            holder.dline.setVisibility(View.GONE);
        }
        holder.names.setText("款项名称：" + bean.paymentName);
        holder.team.setText("律师费：" + bean.shouldCharge);
        holder.creat_people.setText("收款条件：" + bean.condition);
//        if (bean.expectGatheringDate.length() > 8) {
//            String str = bean.expectGatheringDate.substring(0,bean.expectGatheringDate.length() - 8);
//            holder.head_left.setText("收费时间：" + str);
//        } else {
        holder.head_left.setText("收费时间：" + bean.expectGatheringDate);
//        }

        holder.head_right.setText("");
        holder.right_one.setVisibility(View.GONE);
        holder.right_two.setVisibility(View.GONE);
        holder.total.setText(bean.hetong);
        holder.charging_mode.setText(bean.shoufei);
        holder.payment_method.setText(bean.fukuan);
        if ("0".equals(bean.isFirst)) {
            holder.hetong.setVisibility(View.VISIBLE);
            holder.shoufei.setVisibility(View.VISIBLE);
            holder.fukuan.setVisibility(View.VISIBLE);
        } else {
            holder.hetong.setVisibility(View.GONE);
            holder.shoufei.setVisibility(View.GONE);
            holder.fukuan.setVisibility(View.GONE);
        }
        return convertView;
    }

    class ViewHolder {
        TextView head_left, head_right, names, team, creat_people, right_two, right_one;
        TextView total, charging_mode, payment_method;
        AutoRelativeLayout hetong, shoufei, fukuan;
        DashedLine dline;
    }

}
